package cn.zc.auth.service.api.biz;

import cn.tools.core.exception.BizException;
import cn.tools.jwt.client.service.JwtCreateTokenService;


import cn.zc.student.entity.VO.StudentUserVO;
import cn.zc.student.feign.FeignStudentUser;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class AuthStudentBiz {
    @Resource
    private FeignStudentUser feignStudentUser;

    @Resource
    private JwtCreateTokenService jwtCreateTokenService;

    /**
     * 调用远程登录接口，并生成jwt
     * @param userName
     * @param passWord
     * @return
     */
    public String passLogin(String userName,String passWord)  {
        StudentUserVO login = feignStudentUser.Login(userName, passWord);
        String studentInfo = JSONObject.toJSONString(login);
        return createJwt(Map.of("userInfo", studentInfo));
    }


    /**
     * 生成jwt
     * @param info
     * @return
     */
    public String createJwt(Map<String,Object> info){
        try {
            return jwtCreateTokenService.createJwt(info);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("生成jwt失败");
        }
    }

//    /**
//     * 判断学生是否购买课程
//     * @param classIfyId
//     * @param request
//     * @return
//     */
//    public Boolean testedStudent(String classIfyId, HttpServletRequest request) {
//        StudentUserVO studentUserVO = JSONObject.parseObject(request.getHeader(AuthEnum.TOKEN.getValue()), StudentUserVO.class);
//        for (StudentAndClassifyVO classifyVO :studentUserVO.getStudentAndClassifyVO()) {
//            if(classifyVO.equals(classIfyId)){
//                return true;
//            }
//        }
//        return false;
//    }
}
